/*eslint no-script-url: 0*/

import React from 'react'
import PropTypes from 'prop-types'
import {Table, Modal} from 'antd'
import classnames from 'classnames'
import {DropOption} from 'components'
import {Link} from 'react-router-dom'
import AnimTableBody from 'components/DataTable/AnimTableBody'
import styles from './LinkTable.less'

const {confirm} = Modal

const LinkPubTable = ({
                        onDeleteItemPub, isMotion, location, ...tableProps
                      }) => {
  const handleMenuClick = (record, e) => {
    //删除
    if (e.key === "1") {
      confirm({
        title: '是否删除当前项？',
        onOk () {
          onDeleteItemPub({
            linkId: record.linkId,
            portletId: record.portletId,
            pgPletId: record.pgPletId,
            code: record.code,
          })
        },

      })
    }
  }

  const AnimateBody = (props) => {
    return <AnimTableBody {...props} />
  }

  // 是否开启首列多选框
  const rowSelection = {
    getCheckboxProps: record => ({
      disabled: false,
    }),
  }

  // 图片设置
  const rowSettingByLinkImg = text => {
    text = "http://127.0.0.1:9998/upload" + text
    return (<img alt="linkImg" width={24} src={text} />)
  }

  const CommonBody = (props) => {
    return <tbody {...props} />
  }

  const columns = [
    {
      title: '链接标题', dataIndex: 'linkTitle', key: 'linkTitlePub',
      render: text => <a href="javascript:void(0);">{text}</a>,
    },
    {title: 'PORTLET名字', dataIndex: 'portletId', key: 'portletIdPub'},
    // {
    //   title: '链接图片', dataIndex: 'linkImg', key: 'linkImgPub',
    //   render: text => rowSettingByLinkImg(text),
    // },
    {
      title: '链接url', dataIndex: 'linkUrl', key: 'linkUrlPub',
      render: text => text,
    },
    {title: '排序', dataIndex: 'orderIndex', key: 'prderIndexPub'},
    {
      title: '操作',
      key: 'linkOperationPub',
      width: 100,
      fixed: 'right',
      render: (text, record) => {
        return (<DropOption onMenuClick={e => handleMenuClick(record, e)}
                            menuOptions={[{key: '1', name: '删除'}]} />)
      },
    },
  ]


  return (
    <Table
      //dataSource = {data}
      {...tableProps}
      columns={columns}
      bordered={true}
      loading={false}
      showHeader={true}
      rowKey={record => record.pgPletId}
      rowSelection={rowSelection}
      components={{
        body: {wrapper: CommonBody},
      }}
    />
  )
}

LinkPubTable.propTypes = {
  onDeleteItem: PropTypes.func,
  isMotion: PropTypes.bool,
  location: PropTypes.object,

}

export default LinkPubTable
